﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace InControl
{
    public partial class INV_NItem_form : Form
    {
        public INV_NItem_form()
        {
            InitializeComponent();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            try
            {
                if (((INV_MDIParent)this.MdiParent).appDriver.group == "administrators")
                {
                    if (textBox1.Text == "" && comboBox1.SelectedValue.ToString() == "0" &&
                        comboBox2.SelectedValue.ToString() == "0" && comboBox3.SelectedValue.ToString() == "0" &&
                        textBox6.Text == "" && textBox4.Text == "")
                        throw new Exception("please complete form");

                    ((INV_MDIParent)this.MdiParent).appDriver.recordNewItem(textBox1.Text, textBox4.Text, comboBox1.Text, comboBox2.Text, comboBox3.Text, textBox6.Text);
                    Error_form ef = new Error_form();
                    ef.richTextBox1.Text = "successful entry";
                    ef.ShowDialog(this);
                    textBox9.Text = ((INV_MDIParent)this.MdiParent).appDriver.GetStock(textBox1.Text, comboBox1.Text, comboBox2.Text).ToString();
                    ((INV_MDIParent)this.MdiParent).appDriver.FillCombo(comboBox1, "cat_table", "category", "id", 0);
                    ((INV_MDIParent)this.MdiParent).appDriver.FillCombo(comboBox2, "type_table", "type_", "id", 0);
                    ((INV_MDIParent)this.MdiParent).appDriver.FillCombo(comboBox3, "inven_table", "location", "id", 0);
                }
            }
            catch (Exception ex)
            {
                Error_form ef = new Error_form();
                ef.richTextBox1.Text = ex.Message;
                ef.ShowDialog(this);
            }
        }

        private void INV_NItem_Activated(object sender, System.EventArgs e)
        {
            //((INV_MDIParent)this.MdiParent).appDriver.FillCombo(comboBox1, "cat_table", "category", "id");
            //((INV_MDIParent)this.MdiParent).appDriver.FillCombo(comboBox2, "type_table", "type", "id");
        }


        private void INV_NItem_form_Load(object sender, EventArgs e)
        {
                ((INV_MDIParent)this.MdiParent).appDriver.FillCombo(comboBox1, "cat_table", "category", "id", 0);
                ((INV_MDIParent)this.MdiParent).appDriver.FillCombo(comboBox2, "type_table", "type_", "id", 0);
                ((INV_MDIParent)this.MdiParent).appDriver.FillCombo(comboBox3, "inven_table", "location", "id", 0);
        }

        private void pictureBox4_Click(object sender, EventArgs e)
        {
            //panel1.Visible = false;
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            ((INV_MDIParent)this.MdiParent).OpenForm(typeof(INV_office_form));
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
 
        }

        private void Off_New_Panel_Paint(object sender, PaintEventArgs e)
        {

        }

        private void textBox6_TextChanged(object sender, EventArgs e)
        {

        }

        private void Nullify()
        {
             textBox4.Clear(); textBox6.Clear();
            comboBox1.SelectedValue = 0; comboBox2.SelectedValue = 0; comboBox3.SelectedValue = 0;
        }
    }
}
